//
//  CouponDetailViewController.m
//  CouponManager
//
//  Created by BoHyun Jo on 11. 5. 19..
//  Copyright 2011 CJ오쇼핑. All rights reserved.
//

#import "CouponDetailViewController.h"
#import "CouponManagerAppDelegate.h"
#import "CouponManagerViewController.h"
@implementation CouponDetailViewController
@synthesize couponData;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}
-(IBAction)pressButton{
/*
    CouponManagerAppDelegate* appDelegate = (CouponManagerAppDelegate*)[[UIApplication sharedApplication]delegate];
    CouponManagerViewController* couponManagerViewController = appDelegate.viewController;
    NSLog(@"%lf",couponManagerViewController.tabBarController.tabBar.frame.origin.x);
    NSLog(@"%lf",couponManagerViewController.tabBarController.tabBar.frame.origin.y);
    NSLog(@"%d",couponManagerViewController.tabBarController.tabBar.hidden);
    [couponManagerViewController.tabBarController.tabBar setHidden:NO];
 */
    
    UITabBarController *commonTabBarController = (UITabBarController *)self.parentViewController.parentViewController;    
    [commonTabBarController.tabBar setHidden:NO];

  [self.navigationController popViewControllerAnimated:YES];  

    
}
#pragma mark - View lifecycle
/*
-(void)pressedBack
{
	
}


-(void)makeCustomizeBackButton
{
	UIImage *img = [UIImage imageNamed:@"backButton_onNavigation copy.png"];
	UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
	backBtn.frame = CGRectMake(0, 0, 50, 30);
	[backBtn setImage:img forState:UIControlStateNormal];
	[backBtn addTarget:self action:@selector(pressedBack) forControlEvents:UIControlEventTouchUpInside];
	[backButton setTitle:@""
	UIBarButtonItem *back = [[[UIBarButtonItem alloc] initWithCustomView:backBtn] autorelease];
	
	self.navigationItem.leftBarButtonItem = back;	
}
 */

- (void) sliderAction: (UISlider *) sender
{
    NSLog(@"%f",customSlider.value);
	if (customSlider.value != 100.0)  //if the value is not the max, slide this bad boy back to zero
	{
		[sender setValue: 0 animated: YES];
	}
	else {	
        if (customSlider.value == 100.0)  //if the value is max, slide this bad boy back to zero and execute code
        {
            [sender setValue: 0 animated: NO];
            NSLog(@"----");
        }
        // the rest of your code here.
    }
}
- (void)create_Custom_UISlider
{
	CGRect frame = CGRectMake(0.0, 0.0, 300, 52.0);
	CGRect thumb = CGRectMake(0.0, 0.0, 71.0, 47.0);
	customSlider = [[UISlider alloc] initWithFrame:frame];
	[customSlider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
	// in case the parent view draws with a custom color or gradient, use a transparent color
	//customSlider.backgroundColor = [UIColor clearColor];	
    /*
	UIImage *stetchLeftTrack = [[UIImage imageNamed:@"customTrack.png"]
                                stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
	UIImage *stetchRightTrack = [[UIImage imageNamed:@"customTrack.png"]
                                 stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
	[customSlider setThumbImage: [UIImage imageNamed:@"customThumb.png"] forState:UIControlStateNormal];
	[customSlider setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal];
	[customSlider setMaximumTrackImage:stetchRightTrack forState:UIControlStateNormal];
     */
	[customSlider thumbRectForBounds: thumb trackRect: frame value: customSlider.value];
     
	customSlider.minimumValue = 0.0;
	customSlider.maximumValue = 100.0;
	customSlider.continuous = NO;
	customSlider.value = 5.0;
}

- (void)viewDidLoad
{
    
    //[self.navigationItem setHidesBackButton:NO];
    
  //  self.navigationItem.title = couponData.title;
    
    NSLog(@"%@",couponData.title);
    
    
    
    self.navigationItem.leftBarButtonItem = backButton;
    self.navigationItem.rightBarButtonItem = editButton;
    [self create_Custom_UISlider];
    //[customSlider setCenter:CGPointMake(160, 240)];
    [self.view addSubview:customSlider];
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
